/*=============================================================================

  AREA APPLICATION MODULE

  FILE: egm.h
  
  DESCRIPTION

    Module for Application

  EXTERNALIZED FUNCTIONS

    
  Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

                             EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when       who     what, where, why
  ---------  -------  -------------------------------------------------------
   05/26/05   pkim    Version E01.0

=============================================================================*/

/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include <area_mod.h>
#include <math.h>
#include <float.h>
/*=============================================================================
  LOCALIZED FUNCTION DEFINITION
=============================================================================*/

/*=============================================================================
  EXTERNALIZED FUNCTION IMPLEMENTATION
=============================================================================*/
#define EXP_CLOCK			(23230) //(23082) // 23.082kHz
#define EXP_NANOSCALE		(1000000000)
int32 area_exp2nsec(double64 expTIME/*0~100*/)
{
	double64		nsec, clock;
	int32		expTBL; // 1~1000

	expTBL = (int32)(expTIME*10.0);
	expTBL = MAX(expTBL, 0);
	expTBL = MIN(expTBL, 1000);

	clock = (1.0)/(double64)EXP_CLOCK;
	nsec = (double64)(expTBL+1)*(clock)*(double64)EXP_NANOSCALE;
	
	return	(int32)nsec;
}

boolean area_report(void)
{
	SYSmgr				*sm = (SYSmgr*)ObjList_Get(SYS_MGR);
	area_s				*vm = (area_s*)ObjList_Get(AREA_MOD);
	SYSmgr_cfg_s			*sm_cfg;
	area_cfg_s			*ac;
	char					*str;

	if(sm == NULL)
		return FALSE;

	sm_cfg = sm->CFG_Ptr();
	ac = &sm_cfg->area_cfg;

	str = UIstring(NULL);

	UIstring(str);
	
	return TRUE;
}

#define _DOUBLE_NORMAL_			(_FPCLASS_NN | _FPCLASS_NZ | _FPCLASS_PZ | _FPCLASS_PN)
#define _DOUBLE_ZERO_				(_FPCLASS_NZ | _FPCLASS_PZ)

boolean __isnan__(double64 a)
{
	int32			cls;

	cls = _fpclass(a);

	//DBGPRINT("<< 0x%00004X -> 0x%00004X >>", cls, (cls & _DOUBLE_NORMAL_));

	if((cls & _DOUBLE_NORMAL_) != 0x00)
	{
		if((a <= _MX_NAN_) || (a >= DBL_MAX) || (a <= ((-1.0)*(DBL_MAX))))
		{
			//DBGPRINT("[_DBL_RANGE_]");
			return	TRUE;
		}
		
		//DBGPRINT("[%.3f]", a);
		return	FALSE;
	}

	//DBGPRINT("[NAN]");
	
	return	TRUE;
}

double64 __makenan__(void)
{
	static double64		nan_val = sqrt(-1.0);

	return	nan_val;
}

boolean __iszero__(double64 a)
{
	int32			cls;

	cls = _fpclass(a);

	if(cls & _DOUBLE_ZERO_)
	{
		return	TRUE;
	}
	return	FALSE;
}

boolean __issame__(double64 a, double64 b)
{
	return	__iszero__((a-b));
}

/*--- END OF area_util.cpp ---*/
